<?php

/**
 * Description of Offer
 *
 * @author Kam
 */
class Application_Model_DbTable_Catalog extends My_Db_Table {

    protected $_name = 'catalog';
    protected $_primary = 'catalog_id';

    /**
     * 
     * @return Zend_Db_Select
     */
    public function selectActiveEntries() {
        $select = $this->select()
                ->from(array('c' => 'catalog'))
                ->joinLeft(array('i' => 'image'), 'c.image_id=i.image_id', array('image_code' => 'code', 'image_source_id' => 'source_id', 'image_source_name' => 'source_name', 'image_filename' => 'filename'))
                ->joinLeft(array('cc' => 'catalog_category'), 'c.catalog_category_id=cc.catalog_category_id', array('category_name' => 'name', 'category_code' => 'code'))
                ->joinLeft(array('ccp' => 'catalog_category'), 'cc.parent_id=ccp.catalog_category_id', array('parent_category_name' => 'name', 'parent_category_code' => 'code'))
                ->where('cc.is_deleted = 0')
                ->order(array('c.creation_date DESC'))
        ;
        if(!My_Utils::isAdmin()) {
            $select->where('c.active = 1')
                ->where('c.admin_active = 1');
        }
        return $select;
    }

    protected function getMainCodeColumnName() {
        return 'code';
    }

}
